home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
gnu
/
emacs
/
emacs1857
/
bin_d2.zoo
/
lisp
/
cl-indent.el
< prev
next >
Wrap
Lisp/Scheme
|
1991-12-02
|
19KB
|
462 lines
;; Lisp mode, and its idiosyncratic commands.
;; Copyright (C) 1987 Free Software Foundation, Inc.
;; Written by Richard Mlynarik July 1987
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 1, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
;;>> TODO
;; :foo
;; bar
;; :baz
;; zap
;; &key (like &body)??
;; &rest 1 in lambda-lists doesn't work
;; -- really want (foo bar
;; baz)
;; not (foo bar
;; baz)
;; Need something better than &rest for such cases
;;; Hairy lisp indentation.
(defvar lisp-indent-maximum-backtracking 3
"*Maximum depth to backtrack out from a sublist for structured indentation.
If this variable is 0, no backtracking will occur and forms such as flet
may not be correctly indented.")
(defvar lisp-tag-indentation 1
"*Indentation of tags relative to containing list.
This variable is used by the function lisp-indent-tagbody.")
(defvar lisp-tag-body-indentation 3
"*Indentation of non-tagged lines relative to containing list.
This variable is used by the function lisp-indent-tagbody to indent normal
lines (lines without tags).
The indentation is relative to the indentation of the parenthesis enclosing
he special form. If the value is t, the body of tags will be indented
as a block at the same indentation as the first s-expression following
the tag. In this case, any forms before the first tag are indented
by lisp-body-indent.")
(defun common-lisp-indent-hook (indent-point state)
(let ((normal-indent (current-column)))
;; Walk up list levels until we see something
;; which does special things with subforms.
(let ((depth 0)
;; Path describes the position of point in terms of
;; list-structure with respect to contining lists.
;; `foo' has a path of (0 4 1) in `((a b c (d foo) f) g)'
(path ())
;; set non-nil when somebody works out the indentation to use
calculated
(last-point indent-point)
;; the position of the open-paren of the innermost containing list
(containing-form-start (elt state 1))
;; the column of the above
sexp-column)
;; Move to start of innermost containing list
(goto-char containing-form-start)
(setq sexp-column (current-column))
;; Look over successively less-deep containing forms
(while (and (not calculated)
(< depth lisp-indent-maximum-backtracking))
(let ((containing-sexp (point)))
(forward-char 1)
(parse-partial-sexp (point) indent-point 1 t)
;; Move to the car of the relevant containing form
(let (tem function method)
(if (not (looking-at "\\sw\\|\\s_"))
;; This form doesn't seem to start with a symbol
(setq function nil method nil)
(setq tem (point))
(forward-sexp 1)
(setq function (downcase (buffer-substring tem (point))))
(goto-char tem)
(setq tem (intern-soft function)
method (get tem 'common-lisp-indent-hook))
(cond ((and (null method)
(string-match ":[^:]+" function))
;; The pleblisp package feature
(setq function (substring function
(1+ (match-beginning 0)))
method (get (intern-soft function)
'common-lisp-indent-hook)))
((and (null method))
;; backwards compatibility
(setq method (get tem 'lisp-indent-hook)))))
(let ((n 0))
;; How far into the containing form is the current form?
(if (< (point) indent-point)
(while (condition-case ()
(progn
(forward-sexp 1)
(if (>= (point) indent-point)
nil
(parse-partial-sexp (point)
indent-point 1 t)
(setq n (1+ n))
t))
(error nil))))
(setq path (cons n path)))
;; backwards compatibility.
(cond ((null function))
((null method)
(if (null (cdr path))
;; (package prefix was stripped off above)
(setq method (cond ((string-match "\\`def"
function)
'(4 (&whole 4 &rest 1) &body))
((string-match "\\`\\(with\\|do\\)-"
function)
'(4 &body))))))
;; backwards compatibility. Bletch.
((eq method 'defun)
(setq method '(4 (&whole 4 &rest 1) &body))))
(cond ((and (memq (char-after (1- containing-sexp)) '(?\' ?\`))
(not (eql (char-after (- containing-sexp 2)) ?\#)))
;; No indentation for "'(...)" elements
(setq calculated (1+ sexp-column)))
((eql (char-after (1- containing-sexp)) ?\#)
;; "#(...)"
(setq calculated (1+ sexp-column)))
((null method))
((integerp method)
;; convenient top-level hack.
;; (also compatible with lisp-indent-hook)
;; The number specifies how many `distinguished'
;; forms there are before the body starts
;; Equivalent to (4 4 ... &body)
(setq calculated (cond ((cdr path)
normal-indent)
((<= (car path) method)
;; `distinguished' form
(list (+ sexp-column 4)
containing-form-start))
((= (car path) (1+ method))
;; first body form.
(+ sexp-column lisp-body-indent))
(t
;; other body form
normal-indent))))
((symbolp method)
(setq calculated (funcall method
path state indent-point
sexp-column normal-indent)))
(t
(setq calculated (lisp-indent-259
method path state indent-point
sexp-column normal-indent)))))
(goto-char containing-sexp)
(setq last-point containing-sexp)
(if (not calculated)
(condition-case ()
(progn (backward-up-list 1)
(setq depth (1+ depth)))
(error (setq depth lisp-indent-maximum-backtracking))))))
calculated)))
(defun lisp-indent-report-bad-format (m)
(error "%s has a badly-formed %s property: %s"
;; Love them